import 'package:flutter/material.dart';

/// 虚线分割线
class DotDivider extends StatelessWidget {
  /// 分割线颜色
  final Color color;

  /// 分割线点间距
  final double space;

  /// 分割线高度
  final double height;

  /// 分割线点宽度
  final double width;

  /// 分割线对齐方式
  final Axis axis;

  const DotDivider({
    this.color = Colors.grey,
    this.space = 3.0,
    this.height = 2.0,
    this.axis = Axis.horizontal,
    this.width = 1.0,
  });

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
      final boxWidth = constraints.constrainWidth();
      final dashHeight = height;
      final dashCount = (boxWidth / (width + space)).floor();
      return Flex(
        direction: axis,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: List.generate(dashCount, (_) {
          return SizedBox(
            width: width,
            height: dashHeight,
            child: DecoratedBox(decoration: BoxDecoration(color: color)),
          );
        }),
      );
    });
  }
}
